<template>
  <div class="app-container">
    <WarehouseLeaseOperationAdd  ref="openWarehouseLeaseOperationAdd" @refresh="refresh"></WarehouseLeaseOperationAdd>
    <WarehouseLeaseOperationDetail  ref="openWarehouseLeaseOperationDetail" @refresh="refresh"></WarehouseLeaseOperationDetail>
    <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px" :label-position="labelPosition">
        <el-form-item label="客户" prop="khmc">
        <el-input
          v-model="queryParams.khmc"
          placeholder="请输入客户"
          clearable
           @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="仓库" prop="spckmc">
        <el-input
          v-model="queryParams.spckmc"
          placeholder="请输入仓库"
          clearable
           @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="预约状态" prop="stating">
        <el-select
            v-model="queryParams.stating"
            placeholder="请选择预约状态"
            clearable
            @change="changeAppointmentStatus"
        >
            <el-option
                v-for="item in appointmentStatus"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="shzt">
        <el-select
            v-model="queryParams.shzt"
            placeholder="请选择审核状态"
            clearable
            @change="changeAuditStatus"
        >
            <el-option
                v-for="item in auditStatus"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="整租状态" prop="zzzt">
        <el-select
            v-model="queryParams.zzzt"
            placeholder="请选择整租状态"
            clearable
            @change="changeWarehouseLeaseStatus"
        >
            <el-option
                v-for="item in warehouseLeaseStatus"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
     <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" @click="handleWarehouseLeaseOperationAdd" v-hasPermi="['	zhcloud:ckzz:add']">添加整租</el-button>
        </el-col>
    </el-row>
    <el-table
      :data="warehouseLeaseList"
      ref="warehouseLeaseTable"
    >
      <af-table-column type="selection" width="60" align="center" />  
      <af-table-column label="操作" align="center" class-name="small-padding fixed-width" width="60" fixed="left">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleDetail(scope.row)"
          >详细</el-button>
        </template>
      </af-table-column>
      <af-table-column prop="pzbh" label="单据编号" fixed="left" width="150"></af-table-column>
      <af-table-column prop="prrq" label="创建时间"></af-table-column>
      <af-table-column prop="rsopmc" label="创建人"></af-table-column>
      <af-table-column prop="dzbz" label="单据备注"></af-table-column>
      <af-table-column prop="spckmc" label="仓库名称"></af-table-column>
      <af-table-column prop="khmc" label="客户名称"></af-table-column>
      <af-table-column prop="khlx" label="所在系统"></af-table-column>
      <af-table-column prop="ssrqid" label="开始日期"></af-table-column>
      <af-table-column prop="ssrqidn" label="结束日期"></af-table-column>
      <af-table-column prop="sts" label="整租天数"></af-table-column>
      <af-table-column prop="cwmj" label="整租面积"></af-table-column>
      <af-table-column prop="ckrl" label="整租最大容量(吨)"></af-table-column>
      <af-table-column prop="ckdj" label="整租单价(元/平方米)"></af-table-column>
      <af-table-column prop="ckje" label="整租金额"></af-table-column>
      <af-table-column prop="statings" label="预约状态"></af-table-column>
      <af-table-column prop="zzzt" label="整租状态"></af-table-column>
      <af-table-column prop="shzt" label="审核状态"></af-table-column>
    </el-table>
     <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="getList"
      />
  </div>

</template>

<script>
import { getWarehouseLeaseOperation } from "@/api/storage/warehouseLease/warehouseLeaseOperation";
import WarehouseLeaseOperationAdd from './warehouseLeaseOperationAdd.vue'
import WarehouseLeaseOperationDetail from './warehouseLeaseOperationDetail.vue'

export default {
  name: "WarehouseLeaseOperation",
  components:{WarehouseLeaseOperationAdd, WarehouseLeaseOperationDetail},
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //对齐
      labelPosition: "right",
      //预约状态
      appointmentStatus:[{
        value: "0",
        label:"正在预约"
      },{
        value: "1",
        label:"预约驳回"
      },{
        value: "3",
        label:"正式单"
      }],
      //审核状态
      auditStatus:[{
        value: "未审核",
        label:"未审核"
      },{
        value: "已审核",
        label:"已审核"
      }],
      //整租状态
      warehouseLeaseStatus:[{
        value: "尚未开始",
        label:"尚未开始"
      },{
        value: "正在租借",
        label:"正在租借"
      },{
        value: "已超出期限",
        label:"已超出期限"
      }],
      // 查询参数
      queryParams: {
        stating: "",
        khmc: "",
        spckmc:"", 
        zzzt: "",
        shzt: ""
      },
      // 货物入仓列表
      warehouseLeaseList: [],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  beforeRouteEnter(to, from, next) {
    const params = to.params
    next(vm => {   
      if(Object.keys(params).length > 0) {
        if(to.params.refresh == true) {
          vm.getList()
        }
      }
    })
  },
  created() {
    this.getList()
  },
  methods: {
    /** 获取整租操作列表 */
    getList() {
      getWarehouseLeaseOperation(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.warehouseLeaseList = response.rows;
        this.total = response.total;
      });
    },
    /** 预约状态选择 */
    changeAppointmentStatus() {
      this.getList()
    },
    /** 审核状态选择 */
    changeAuditStatus() {
      this.getList()
    },
     /** 整租状态选择 */
    changeWarehouseLeaseStatus() {
      this.getList()
    },

    /**添加整租 */
    handleWarehouseLeaseOperationAdd() {
      this.$refs.openWarehouseLeaseOperationAdd.open()
    },

    /**操作详情 */
    handleDetail(data) {
      this.$refs.openWarehouseLeaseOperationDetail.open(data)
    },

    //合计
    // getSummaries({ columns, data }) {
    //   const sums = []
    //   columns.forEach((column, index) => {
    //     if(index === 0) {
    //       sums[index] = "合计"
		// 	    return
    //     }
    //     if ((column.property === "spjs" || column.property === "spsl")) {
    //       const values = data.map((item) => {
    //         return parseFloat(this.delcommafy(item[column.property]))
    //       });
    //       sums[index] = values.reduce((prev, curr) => {
    //         return prev + curr
    //       }, 0);
    //     }
    //   })
    //   return sums
    // },
       /**enter键触发 */
    enterClick(e) {
      this.getList()
    },
    /** 刷新数据*/
    refresh() {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.getList()
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
  }
};
</script>
